
<div class="easyui-layout" data-options="fit:true"  style="margin:5px">
    <!-- Begin of toolbar -->
    <div data-options="region:'center',border:false">
    <!-- Begin of 工具条 -->
    <div id="role-toolbar" style="margin:5px">
        <div>
        <@shiro.hasPermission name="Role:create"> 
        	<a href="javascript:;" class="easyui-linkbutton" iconCls="icon-add"  onclick="openAddRole()" plain="false">添加</a>
         </@shiro.hasPermission>
         <@shiro.hasPermission name="Role:update">    
            <a href="javascript:;" class="easyui-linkbutton" iconCls="icon-edit" onclick="openEditRole()" plain="false">修改</a>
         </@shiro.hasPermission>
        <@shiro.hasRole name="sootry">
            <a href="javascript:;" class="easyui-linkbutton" iconCls="icon-edit" onclick="perSet()" plain="flase">权限设置</a>
         </@shiro.hasRole>   
<!--             <a href="javascript:;" class="easyui-linkbutton" iconCls="icon-remove" onclick="removeRole()" plain="false">停用</a> -->
<!--             <a href="javascript:;" class="easyui-linkbutton" iconCls="icon-reload" onclick="remove()" plain="false">分配权限</a> -->
            &nbsp;<label>角色名：</label><input  class="easyui-textbox" id="uname"  style="width:100px">
            <a href="javascript:;" id ="role-search" class="easyui-linkbutton" iconCls="icon-search">搜索</a>
        </div>
    </div>
    <!-- end of 工具条-->
	<table id="role-datagrid"></table>
    </div>
</div>

<div id="perset-dialog" > </div>

<!-- Begin of 新增、编辑 -->
<div id="role-dialog" class="easyui-dialog" data-options="closed:true,iconCls:'icon-save'" style="width:400px; padding:10px;">
	<form id="role-form" method="post">
        <table>
            <tr>
                <td width="60" align="right">角色名称:</td>
                <td><input data-options="required:true" type="text" name="roleName" class="easyui-textbox" /></td>
            </tr>
            <tr>
                <td align="right">角色描述:</td>
                <td><input data-options="required:true" type="text" name="roleDescription" class="easyui-textbox" /></td>
            </tr>
<!--             <tr> -->
<!--                 <td align="right">菜单权限:</td> -->
<!--                 <td> -->
<!--            	    	<select id="rmTree" name="menuIds" multiple   style="width:200px;"></select> -->
<!--                 </td> -->
<!--             </tr> -->
        </table>
        <input type="hidden" name="roleId"/>
    </form>
</div>

<!-- End of 新增、编辑 -->
<script type="text/javascript">

	$(function(){
		//搜索
		$("#role-search").click(function(){
			$("#role-datagrid").datagrid('load', {
				roleName: $("#uname").val()
			});
		});
		//树菜单
// 	    $("#rmTree").combotree({
// 	        url: 'menu/getMenuComTree',
// 	        required: false,
// 	        editable:false,
// 	        onlyLeafCheck:true
// 	    });
	})
	/**
	* 用户 删除记录
	*/
// 	function removeRole(){
// 		var items = $('#role-datagrid').datagrid('getSelections');
// 		if(items.length >0){
// 			$.messager.confirm('信息提示','确定要？', function(result){
// 				if(result){
// 					var ids = "";
// 					$(items).each(function(){
// 						ids += this.userId+","
// 					});
// 					$.ajax({
// 						url:'user/delUser',
// 						data:{"ids":ids},
// 						success:function(data){
// 							if(data){
// 								$.messager.alert('信息提示','删除成功！','info');		
// 								$('#role-datagrid').datagrid('reload');  
// 							}
// 							else
// 							{
// 								$.messager.alert('信息提示','删除失败！','info');		
// 							}
// 						}	
// 					});
// 				}	
// 			});
// 		}else{
// 			$.messager.alert('信息提示','请至少选择一条记录！','info');		
// 		}
// 	}
	
	/**
	*  打开添加窗口
	*/
	function openAddRole(){
		$('#role-form').form('clear');
		$('#role-dialog').dialog({
			closed: false,
			modal:true,
            title: "角色新增",
            buttons: [{
                text: '确定',
                iconCls: 'icon-ok',
                handler: addRole
            }, {
                text: '取消',
                iconCls: 'icon-cancel',
                handler: function () {
                    $('#role-dialog').dialog('close');                    
                }
            }]
        });
	}
	
	/**
	* 用户 打开修改窗口
	*/
	function openEditRole(){
		$('#role-form').form('clear');
		var item = $('#role-datagrid').datagrid('getSelections');
		if(item && item.length ==1){
			//加载表单数据
			$('#role-form').form('load', "role/getRoleById?uid="+item[0].roleId);
			$('#role-dialog').dialog({
				closed: false,
				modal:true,
	            title: "用户修改",
	            buttons: [{
	                text: '确定',
	                iconCls: 'icon-ok',
	                handler: editRole
	            }, {
	                text: '取消',
	                iconCls: 'icon-cancel',
	                handler: function () {
	                    $('#role-dialog').dialog('close');                    
	                }
	            }]
	        });
		}else{
			$.messager.alert('信息提示','请选中一条记录进行修改！','info');	
		}
		
	}	
	
	
	function perSet() {
		var row = $("#role-datagrid").datagrid("getSelected");
		if (row == null) {
			$.messager.alert("操作提示", "请选择一条记录进行操作！", "info");
			return false;
		}
		
		$('#perset-dialog').dialog({
		    title: '角色权限',
		    width: 800,
		    height: 500,
		    closed: false,
		    cache: false,
		    href: 'role/perSet?rid='+row.roleId+'',
		    modal: true,
		    maximizable:true
		});
	}
	
	/**
	*  添加记录
	*/
	function addRole(){
		//获取选中菜单id集合
// 		var mids = $('#rmTree').combotree('getValues');	
		$('#role-form').form('submit', {
			url:'role/addRole',
			success:function(data){
				if(data){
					$.messager.alert('信息提示','提交成功！','info');
					$('#role-dialog').dialog('close');
					$('#role-datagrid').datagrid('reload');  
				}
				else
				{
					$.messager.alert('信息提示','提交失败！','info');
				}
			}
		});
	}
	
	/**
	*  修改记录
	*/
	function editRole(){
		$('#role-form').form('submit', {
			url:'role/editRole',
			success:function(data){
				if(data){
					$.messager.alert('信息提示','提交成功！','info');
					$('#role-dialog').dialog('close');
					$('#role-datagrid').datagrid('reload');  
				}
				else
				{
					$.messager.alert('信息提示','提交失败！','info');
				}
			}
		});
	}
	
	
	/**
	* 载入数据
	*/
	$("#role-datagrid").datagrid({
		url:'role/rolelist',
		rownumbers:true,
		singleSelect:false,
		pageSize:30,           
		pagination:true,
		multiSort:true,
		fitColumns:true,
		fit:true,
		singleSelect:true,
		toolbar: "#role-toolbar",
		columns:[[
			{ field:'roleName',title:'角色名',width:100},
			{ field:'roleDescription',title:'角色描述',width:100},
			{ field:'menuList',title:'拥有菜单权限',width:200},
			{ field:'available',title:'状态',width:200,
				formatter: function(value,row,index){
					if(value == "0"){
						return "正常";
					}else{
						return "<font color='#d15b47'>已停用</font>";
					}
				}	
			}
			
		]]
	});
</script>
